#include"Stack.h"
void STPrint(ST s)
{
	for (int i = 0; i < s.size; i++)
	{
		printf(" %d", s.a[i]);
	}
	printf("\n");
}
void STInit(ST* ps)
{
	assert(ps);
	ps->a = NULL;
	ps->capacity = ps->size = 0;
}
void STDestory(ST* ps)
{
	assert(ps);
	free(ps->a);
	ps->a = NULL;
	ps->capacity = ps->size = 0;
}
void STPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps->capacity == ps->size)
	{
		int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
		STDataType* tmp = (STDataType*)realloc(ps->a, sizeof(STDataType) * newcapacity);
		if (tmp == NULL)
		{
			perror("realloc fail");
			return;
		}
		ps->capacity = newcapacity;
		ps->a = tmp;
	}
	ps->a[ps->size++] = x;
}
void STPop(ST* ps)
{
	assert(ps);
	assert(ps->size);
	ps->size--;
}
STDataType STTop(ST s)
{
	assert(s.size);
	return s.a[s.size - 1];
}
bool STEmpty(ST s)
{
	return s.size == 0;
}
int STSize(ST s)
{
	return s.size;
}

